import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:xws/utils/theme_util.dart';

import 'refresh_view.dart';

///空视图
class EmptyView extends StatelessWidget {
  const EmptyView({
    Key? key,
    this.content,
    this.onRefresh,
  }) : super(key: key);

  ///文本
  final String? content;

  ///刷新
  final Future<void> Function(RefreshController controller)? onRefresh;

  @override
  Widget build(BuildContext context) {
    Widget child = Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        Icon(
          Icons.layers_rounded,
          size: 150,
          color: black(context).withOpacity(0.1),
        ),
        const SizedBox(height: 14),
        Text(
          content ?? '暂无数据',
          textAlign: TextAlign.center,
          style: const TextStyle(fontSize: 14),
        ),
      ],
    );

    if (onRefresh != null) {
      child = RefreshView(
        onRefresh: onRefresh,
        child: child,
      );
    }

    return child;
  }
}
